package com.neusoft.SPNursingHome.service;

import java.util.concurrent.TimeUnit;

import com.neusoft.SPNursingHome.redisDao.RedisDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

// Dao层专用注解
@Repository
@Primary
public class RadisDaoImpl implements RedisDao {
	@Autowired
	private RedisTemplate redisTemplate;
	
	@Override
	public void set(String key, String value) {
		// TODO Auto-generated method stub
		ValueOperations vo = redisTemplate.opsForValue();
		// 向redis中存储键值对
		vo.set(key, value);
		vo.set(key, value, 0, null);
	}

	@Override
	public String get(String key) {
		// TODO Auto-generated method stub
		ValueOperations vo = redisTemplate.opsForValue();
		String val = (String)vo.get(key);
		return val;
	}
	
	@Override
	public void set(String key, String value, long time, TimeUnit unit) {
		ValueOperations vo = redisTemplate.opsForValue();
		// 调用带过期时间的存储方法
		vo.set(key, value, time, unit);
	}

}
